/**
* Utility class for Board and State
*/
public class State {
    /*
     * if sent to Board state equals
     *  0: new game
     *  1: deal hands
     *  2: place bets
     *  3: begin round
     *  4: display round scores
     *  5: deal next round
     *  6: game over
     *  
	 *  possible new state set
	 *  0: main menu
	 *  1: settings
	 *  2: statistics
	 *  3: new game
     *  4: deal hands
     *  5: place bets
     *  6: begin round
     *  7: display round scores
     *  8: deal next round
     *  9: game over
     * 10: exit
     * 11: new game (flush all vars)
     */
    int state;
    int prevState;
    int nsScore = 0;
    int ewScore = 0;
    /*
     * stores position of the dealer
     */
    int dealer = 0;
    //holds all 4 players hands
    Card[][] hand = new Card[4][13];
    //holds the cards
    Deck deck = new Deck();
    //keeps current round of the game
    int round = 0;
    //becomes true when spades are broken
    boolean spadesAllowed = false;
    //bags
    int[] bags = new int[2];
    public State()
    {
        state = 0;
        prevState = 0;
    }
    public int getState()
    {
        return state;
    }
    public void setState(int s)
    {
    	prevState = state;
        if(!valid())
            throw new IllegalStateException();	
        else
            state = s;
    }
    private boolean valid()
    {
        return !(state<0 || state>11);
    }
    public void deal()
    {
         deck.dealHands();
         hand = deck.getHands();
         deck = new Deck();
    }
    public int getRound()
    {
        return round;
    }
    public void setRound(int r)
    {
        round = r;
    }

    Card[] getHand(int ctr) {
        return hand[ctr];
    }
    public void updateHands(Card[][] hs)
    {
    	hand = hs;
    }
    public int getDealer()
    {
    	return dealer;
    }
    public void setDealer(int l)
    {
    	if(l==4)
    		l = 0;
    	dealer = l;
    }
    public void setSpadesAllowed()
    {
    	spadesAllowed = true;
    }
    public boolean getSpadesAllowed()
    {
    	return spadesAllowed;
    }
    public void setNSScore(int score)
    {
    	nsScore = score;
    }
    public void setEWScore(int score)
    {
    	ewScore = score;
    }
    public int getNSScore()
    {
    	return nsScore;
    }
    public int getEWScore()
    {
    	return ewScore;
    }
    public void setNSBags(int bag)
    {
    	bags[0] = bag;
    }
    public int getNSBags()
    {
    	return bags[0];
    }
    public void setEWBags(int bag)
    {
    	bags[1] = bag;
    }
    public int getEWBags()
    {
    	return bags[1];
    }
    public int getPrevState()
    {
    	return prevState;
    }
}
